 package org.zlb.netty.client.serial;

import org.zlb.netty.dbo.SubReq;
import org.zlb.netty.dbo.SubResp;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class SubReqClientHandler extends ChannelInboundHandlerAdapter {

    
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        for (int i=0; i<10; i++) {
            SubReq req = new SubReq();
            req.setSubReqId(i);
            req.setUserName("zlb");
            req.setUserPhone("13512345678");
            req.setAddress("cswcjxl");
            
            ctx.write(req);
        }
        ctx.flush();
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        SubResp resp = (SubResp) msg;
        System.out.println(resp.getSubReqId() + "-" + resp.getDesc());
        ctx.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

}
